/**
 *  @file CppflibMain.cpp
 */
#if defined(WIN32)
#   include <windows.h>
#elif defined(linux)
#   include <errno.h>
#endif
#include "commontypes.h"
#include "CppflibBuildNum.h"

namespace cppflib
{

#define FLIB_MAJOR 0
#define FLIB_MINOR 1
#define FLIB_REV   0

_DLLAPI u32_t GetflibVerMajor(void)
{
   return FLIB_MAJOR;
}

_DLLAPI u32_t GetflibVerMinor(void)
{
   return FLIB_MINOR;
}

_DLLAPI u32_t GetflibVerRev(void)
{
   return FLIB_REV;
}

_DLLAPI u32_t GetflibVerBuild(void)
{
   return FLIB_BUILD;
}

_DLLAPI pcwstr_t GetflibVerString(void)
{
   return NUM2STR(FLIB_MAJOR) _S(".") NUM2STR(FLIB_MINOR) _S(".") NUM2STR(FLIB_REV) _S(".") NUM2STR(FLIB_BUILD);
}

/**
 *  Get error code for different platform
 *
 *  @return an integer (on Windows, it should be unsigned while on Linux, it is signed
 */
_DLLAPI int GetLastError(void)
{
#if defined(WIN32)
   return static_cast<int>(::GetLastError());
#elif defined(linux)
   return errno;
#endif
}

/**
 *  To test if this machine is little endian
 */
_DLLAPI bool IsLittleEndian(void)
{
   int n = 0x01020304;
   u8_t * pInt = reinterpret_cast<u8_t*>(&n);
   return (*pInt == 0x04);
}

} // end of namespace cppflib
